home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 44
/
Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso
/
Aminet
/
comm
/
mail
/
YAM23src.lha
/
Source
/
extrasrc
/
strsfn.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-02-16
|
1KB
|
61 lines
#include <string.h>
#include "extra.h"
/* Build a filename from its components */
void strsfn(const char *file, char *drive, char *path, char *node, char *ext)
{
const char *end = file + strlen(file);
const char *p = file;
while (*p && *p != ':')
++p;
if (*p++ == ':')
{
if (drive)
{
memcpy(drive, file, p - file);
drive += p - file;
}
file = p;
}
if (drive)
*drive = '\0';
p = end;
while (p > file && p[-1] != '.' && p[-1] != '/')
--p;
if (ext)
{
if (p > file && end - p < FESIZE)
memcpy(ext, p, end - p + 1);
else
*ext = '\0';
}
if (p > file)
end = p - 1;
p = end;
while (p > file && p[-1] != '/')
--p;
if (node)
{
if (end > p && end - p < FNSIZE)
{
memcpy(node, p, end - p);
node += end - p;
}
*node = '\0';
}
end = p > file ? p - 1 : p;
if (path && end > p && end - p < FMSIZE)
{
memcpy(path, p, end - p);
path += end - p;
}
if (path)
*path = '\0';
}